#include <REGX52.H>
#include "key.h"
#include "timer0.h"
#include "nixie.h"

sbit MOTER = P1^0;

// 计数值和比较值，用于输出PWM
unsigned char count, compare;
unsigned char keyNumber, speed;

void main()
{
	timer0_init();	
	while(1)
	{
		keyNumber = getKeyNumber();
		if(keyNumber == 1)
		{
			speed++;
			// 若是speed超过4则回到0
			speed = speed % 4;
			// 设置比较值，改变占空比
			if(speed == 0){compare = 0;}
			if(speed == 1){compare = 50;}
			if(speed == 2){compare = 75;}
			if(speed == 3){compare = 100;}
		}
		nixieTube(1, speed);
	}
}

void Time0_Rountine() interrupt 1
{
	TL0 = 0xA4;		//设置定时初值
	TH0 = 0xFF;		//设置定时初值
	count++;
	count %= 100; // 计数值控制在0-99
	// 若计数值小于比较值
	if(count < compare)
	{
		MOTER = 1;
	}
	// 若计数值大于等于比较值
	else
	{
		MOTER = 0;
	}
}
